library(plotly)
## Warning: package 'plotly' was built under R version 4.1.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.1.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
df <- USArrests
df$region <- tolower(rownames(USArrests))
#Data Visualization:
fig <- plot_ly(x = df$UrbanPop,
y = df$Murder,
type = "scatter",
mode = "markers",
color = df$region)
fig <- fig %>% layout(title = 'Urban Population vs. Murder Arrests by State',
xaxis = list(title = '% Urban Population'),
yaxis = list(title = 'Murder Arrests (per 100,000'))
fig
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors